//
//  TabSwitchView.swift
//
//  Created by Apple on 2021/6/10.
//

/*
 参数：
 url：上个页面的url
 callBack(可选):使用的回调函数
 */

import SwiftUI

struct TabSwitchView: View {
    @EnvironmentObject var modelData:TabItemsModelData
    var width: CGFloat = UIScreen.main.bounds.width
    var height: CGFloat = UIScreen.main.bounds.height
    var callback: TabSwitchCallBack?
    @State var isScrolling: Bool = false
    @State var opacity = 0.0
    
    var body: some View {
        withAnimation{
            VStack{
                NavigationBar(isScrolling:isScrolling ,callback:callback)
                    .zIndex(2)
                ZStack{
                    TabList(isScrolling:$isScrolling, callback:callback)
                        .padding(EdgeInsets(top:-12.0, leading: 0, bottom: 0, trailing: 0))
                        .zIndex(0)
                    VStack{
                        Spacer()
                        Clear(callback:callback)
                            .padding()
                            
                    }
                    .zIndex(100)
                }.opacity(opacity)
                
                //.transition(.slide).animation(.easeInOut(duration: 0.2))
            }
            .toast(isPresenting:$modelData.toast , alert: {
                AlertToast.init(displayMode: .hud, type: .regular, title: modelData.displayMode ? "safari风格":"chrome风格")
            })
            .onAppear(perform: {
                withAnimation(.easeInOut(duration: 0.8), {
                    opacity = 1.0
                    
                })
            })
            .onDisappear(perform: {
                withAnimation(.easeInOut(duration: 0.8), {
                    opacity = 0.0
                })
            })
            
        }
    }
}

struct TabSwitch_Previews: PreviewProvider {
    static var previews: some View {
        TabSwitchView().environmentObject(TabItemsModelData())
    }
}

